package com.tbit.main.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import com.tbit.main.common.JsonResult;
import com.tbit.main.constant.AccountDayStatConstant;
import com.tbit.main.constant.UserConstant;
import com.tbit.main.pojo.*;
import com.tbit.main.service.*;
import com.tbit.main.util.Assert;
import com.tbit.main.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.DecimalFormat;
import java.util.*;

/**
 * 运营分析 多个区域对比
 *
 * @author LMY
 * @create 2020-12-21 17:27
 */
@RestController
@RequestMapping("/operationReports")
public class OperationReportsController {
    @Autowired
    private MachineService machineService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private UserService userService;
    @Autowired
    private AccountService accountService;
    @Autowired
    private RideOrderDayStaService rideOrderDayStaService;
    @Autowired
    private DispatchDayStaService dispatchDayStaService;
    @Autowired
    private MoveDayStaService moveDayStaService;
    @Autowired
    private PowerDayStaService powerDayStaService;
    @Autowired
    private MachineDayStaService machineDayStaService;
    @Autowired
    private AccountUserService accountUserService;
    @Autowired
    private GeoreGionService georeGionService;
    @Autowired
    private GeoreMachineService georeMachineService;
    @Autowired
    private AccountDayStatService accountDayStatService;
    @Autowired
    private AccountSumStatService accountSumStatService;

    /**
     * 车均收入
     */
    @RequestMapping("/carAverage")
    public JsonResult<List<List<OperationData<Float>>>> carAverageEarning(Operation operation) {

        Assert.hasLength(operation.getStartTime(), "System.startTime.notNull");
        Assert.hasLength(operation.getEndTime(), "System.endTime.notNull");

        /**区域分区名字*/
        Map<String, String> names = new HashMap<>();

        /**区域车辆*/
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            /**获取区域名称*/
            List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
            for (Account account : accountList) {
                names.put("accountId_" + account.getAccountId(), account.getName());
            }
        }

        /**分区车辆*/
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            /**获取分区名称*/
            List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
            for (GeoreGion georeGion : geoRegions) {
                names.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
            }
        }

        if (operation.getType() == null) {
            operation.setType(1);
        }

        List<RideOrderDaySta> rideOrderDayStaList;
        Map<String, RideOrderDaySta> mapRid = new TreeMap<>(Comparator.naturalOrder());
        /**日统计*/
        if (operation.getType().equals(1)) {
            if (DateTimeUtil.getYYMMDD(operation.getEndTime()).equals(DateTimeUtil.getNowTimeYMD())) {
                operation.setEndTime(DateTimeUtil.getEndDateTimeBefore(-1));
            }
            rideOrderDayStaList = rideOrderDayStaService.getByAccountIdDateDay(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (RideOrderDaySta rideOrderDaySta : rideOrderDayStaList) {
                if (rideOrderDaySta.getRegionId() != null) {
                    mapRid.put(rideOrderDaySta.getOrderDate() + "regionId_" + rideOrderDaySta.getRegionId(), rideOrderDaySta);
                } else {
                    mapRid.put(rideOrderDaySta.getOrderDate() + "accountId_" + rideOrderDaySta.getAccountId(), rideOrderDaySta);
                }
            }
        }
        /**周统计*/
        else if (operation.getType().equals(2)) {
            rideOrderDayStaList = rideOrderDayStaService.getByAccountIdDateWeek(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (RideOrderDaySta rideOrderDaySta : rideOrderDayStaList) {
                if (rideOrderDaySta.getRegionId() != null) {
                    mapRid.put(rideOrderDaySta.getDateWeek() + "regionId_" + rideOrderDaySta.getRegionId(), rideOrderDaySta);
                } else {
                    mapRid.put(rideOrderDaySta.getDateWeek() + "accountId_" + rideOrderDaySta.getAccountId(), rideOrderDaySta);
                }
            }
        }
        /** 月统计*/
        else if (operation.getType().equals(3)) {
            rideOrderDayStaList = rideOrderDayStaService.getByAccountIdDateMonth(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (RideOrderDaySta rideOrderDaySta : rideOrderDayStaList) {
                if (rideOrderDaySta.getRegionId() != null) {
                    mapRid.put(rideOrderDaySta.getDateMonth() + "regionId_" + rideOrderDaySta.getRegionId(), rideOrderDaySta);
                } else {
                    mapRid.put(rideOrderDaySta.getDateMonth() + "accountId_" + rideOrderDaySta.getAccountId(), rideOrderDaySta);
                }
            }
        }

        /**拼接数据*/
        Map<String, List<OperationData<Float>>> mapNew = new HashMap<>();
        for (String keyIdDate : mapRid.keySet()) {
            String keyId = null;
            if (operation.getType().equals(1)) {
                keyId = keyIdDate.substring(10);
            } else if (operation.getType().equals(2)) {
                keyId = keyIdDate.substring(6);
            } else if (operation.getType().equals(3)) {
                keyId = keyIdDate.substring(7);
            }
            if (mapNew.get(keyId) == null) {
                List<OperationData<Float>> operationDataList = new LinkedList<>();

                OperationData<Float> operationDataCount = new OperationData<>();
                OperationData<Float> operationDataMoney = new OperationData<>();

                operationDataCount.setName(names.get(keyId));
                operationDataMoney.setName(names.get(keyId));

                // 车均订单
                List<Float> dataCounts = new LinkedList<>();
                float dataCount;

                // 车均金额
                List<Float> dataMoneys = new LinkedList<>();
                float dataMoney;

                DecimalFormat df = new DecimalFormat("0.00");
                if (mapRid.get(keyIdDate).getMachineCount() == null || mapRid.get(keyIdDate).getMachineCount() == 0) {
                    dataCount = (float) 0.00;
                    dataMoney = (float) 0.00;
                } else {
                    if (mapRid.get(keyIdDate).getMeanOrderCount() == null || mapRid.get(keyIdDate).getMeanOrderCount().equals(0.00)) {
                        dataCount = (float) NumberUtil.div(Float.parseFloat(mapRid.get(keyIdDate).getOrderCount() + ""), Float.parseFloat(mapRid.get(keyIdDate).getMachineCount() + ""), 2);
                        dataMoney = (float) NumberUtil.div(NumberUtil.div(Float.parseFloat(mapRid.get(keyIdDate).getOrderMoney() + ""), 100, 2), Float.parseFloat(mapRid.get(keyIdDate).getMachineCount() + ""), 2);
                    } else {
                        dataCount = Float.parseFloat(df.format(mapRid.get(keyIdDate).getMeanOrderCount()));
                        dataMoney = Float.parseFloat(df.format(mapRid.get(keyIdDate).getMeanOrderMoney() / 100));
                    }

                }
                dataCounts.add(dataCount);
                operationDataCount.setData(dataCounts);
                dataMoneys.add(dataMoney);
                operationDataMoney.setData(dataMoneys);

                // 时间
                List<String> times = new LinkedList<>();
                List<String> weeks = new LinkedList<>();
                String time;
                String week;

                if (operation.getType().equals(1)) {
                    time = mapRid.get(keyIdDate).getOrderDate();
                    times.add(time);
                } else if (operation.getType().equals(2)) {
                    time = mapRid.get(keyIdDate).getOrderDate();
                    week = mapRid.get(keyIdDate).getDateWeek();
                    times.add(time);
                    weeks.add(week);
                } else if (operation.getType().equals(3)) {
                    time = mapRid.get(keyIdDate).getDateMonth();
                    times.add(time);
                }

                operationDataCount.setTime(times);
                operationDataCount.setWeek(weeks);
                operationDataMoney.setTime(times);
                operationDataMoney.setWeek(weeks);

                operationDataList.add(operationDataCount);
                operationDataList.add(operationDataMoney);
                mapNew.put(keyId, operationDataList);
            } else {
                DecimalFormat df = new DecimalFormat("0.00");
                if (mapRid.get(keyIdDate).getMachineCount() == null || mapRid.get(keyIdDate).getMachineCount() == 0) {
                    mapNew.get(keyId).get(0).getData().add((float) 0.00);
                    mapNew.get(keyId).get(1).getData().add((float) 0.00);
                } else {
                    if (mapRid.get(keyIdDate).getMeanOrderCount() == null || mapRid.get(keyIdDate).getMeanOrderCount().equals(0.00)) {
                        mapNew.get(keyId).get(0).getData().add((float) NumberUtil.div(mapRid.get(keyIdDate).getOrderCount().floatValue(), mapRid.get(keyIdDate).getMachineCount().floatValue(), 2));
                        mapNew.get(keyId).get(1).getData().add((float) NumberUtil.div(NumberUtil.div(mapRid.get(keyIdDate).getOrderMoney().floatValue(), 100, 2), mapRid.get(keyIdDate).getMachineCount().floatValue(), 2));
                    } else {
                        mapNew.get(keyId).get(0).getData().add(Float.parseFloat(df.format(mapRid.get(keyIdDate).getMeanOrderCount())));
                        mapNew.get(keyId).get(1).getData().add(Float.parseFloat(df.format((mapRid.get(keyIdDate).getMeanOrderMoney()) / 100)));
                    }

                }
                if (operation.getType().equals(1)) {
                    mapNew.get(keyId).get(0).getTime().add(mapRid.get(keyIdDate).getOrderDate());
                } else if (operation.getType().equals(2)) {
                    mapNew.get(keyId).get(0).getTime().add(mapRid.get(keyIdDate).getOrderDate());
                    mapNew.get(keyId).get(0).getWeek().add(mapRid.get(keyIdDate).getDateWeek());
                } else if (operation.getType().equals(3)) {
                    mapNew.get(keyId).get(0).getTime().add(mapRid.get(keyIdDate).getDateMonth());
                }
            }
        }

        int size = 0;
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            size += operation.getAccountIds().size();
        }
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            size += operation.getRegionId().size();
        }

        if (mapNew.size() != size) {
            Map<String, Integer> integerMap = new HashMap<>();
            Map<String, String> nameMaps = new HashMap<>();

            if (CollUtil.isNotEmpty(operation.getAccountIds())) {
                for (Integer a : operation.getAccountIds()) {
                    integerMap.put("accountId_" + a, a);
                }

                /**获取区域名称*/
                List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
                for (Account account : accountList) {
                    nameMaps.put("accountId_" + account.getAccountId(), account.getName());
                }

            }
            if (CollUtil.isNotEmpty(operation.getRegionId())) {
                for (Integer r : operation.getRegionId()) {
                    integerMap.put("regionId_" + r, r);
                }

                /**获取分区名称*/
                List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
                for (GeoreGion georeGion : geoRegions) {
                    nameMaps.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
                }
            }

            for (String key : integerMap.keySet()) {
                if (mapNew.get(key) == null) {
                    List<OperationData<Float>> operationDataList = new LinkedList<>();

                    OperationData<Float> operationDataCount = new OperationData<>();
                    OperationData<Float> operationDataMoney = new OperationData<>();

                    operationDataCount.setName(nameMaps.get(key));
                    operationDataMoney.setName(nameMaps.get(key));

                    // 车均订单
                    List<Float> dataCounts = new LinkedList<>();
                    // 车均金额
                    List<Float> dataMoneys = new LinkedList<>();

                    Float dataCount = (float) 0.00;
                    Float dataMoney = (float) 0.00;

                    dataCounts.add(dataCount);
                    dataMoneys.add(dataMoney);

                    operationDataCount.setData(dataCounts);
                    operationDataMoney.setData(dataMoneys);

                    // 时间
                    List<String> times = new LinkedList<>();
                    List<String> weeks = new LinkedList<>();
                    String time;
                    String week;

                    if (operation.getType().equals(1)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        times.add(time);
                    } else if (operation.getType().equals(2)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        week = DateTimeUtil.getStringWeek(operation.getStartTime());
                        times.add(time);
                        weeks.add(week);
                    } else if (operation.getType().equals(3)) {
                        time = operation.getStartTime().substring(0, 7);
                        times.add(time);
                    }
                    operationDataCount.setTime(times);
                    operationDataCount.setWeek(weeks);
                    operationDataMoney.setTime(times);
                    operationDataMoney.setWeek(weeks);

                    operationDataList.add(operationDataCount);
                    operationDataList.add(operationDataMoney);
                    mapNew.put(key, operationDataList);
                }
            }
        }

        List<List<OperationData<Float>>> operationDataList = new LinkedList<>();
        for (String key : mapNew.keySet()) {
            operationDataList.add(mapNew.get(key));
        }

        for (List<OperationData<Float>> operationData : operationDataList) {
            /**补充数据*/
            if (operation.getType().equals(1)) {
                List<String> list = DateTimeUtil.findDates(operation.getStartTime(), operation.getEndTime());
                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                Map<String, Float> listMoney = new TreeMap<>(Comparator.naturalOrder());
                for (String i : list) {
                    listDate.put(i, (float) 0.00);
                    listMoney.put(i, (float) 0.00);
                }

                List<String> time = new LinkedList<>();
                List<Float> dateCount = new LinkedList<>();
                List<Float> dateMoney = new LinkedList<>();

                if (CollUtil.isNotEmpty(operationData)) {
                    time = operationData.get(0).getTime();
                    dateCount = operationData.get(0).getData();
                    dateMoney = operationData.get(1).getData();
                }

                if (time.size() != listDate.size()) {
                    Map<String, Float> mapCount = new TreeMap<>();
                    Map<String, Float> mapMoney = new TreeMap<>();
                    for (int i = 0; i < dateCount.size(); i++) {
                        mapCount.put(time.get(i), dateCount.get(i));
                        mapMoney.put(time.get(i), dateMoney.get(i));
                    }
                    listDate.putAll(mapCount);
                    listMoney.putAll(mapMoney);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    List<Float> moneyMap = new LinkedList<>();
                    for (String key : listDate.keySet()) {
                        timeMap.add(key);
                        dateMap.add(listDate.get(key));
                        moneyMap.add(listMoney.get(key));
                    }
                    if (CollUtil.isNotEmpty(operationData)) {
                        operationData.get(0).setTime(timeMap);
                        operationData.get(0).setData(dateMap);
                        operationData.get(1).setTime(timeMap);
                        operationData.get(1).setData(moneyMap);
                    }
                }
            } else if (operation.getType().equals(2)) {
                Map<String, String> listTime = DateTimeUtil.getDayOfWeekWithinDateInterval(operation.getStartTime(), operation.getEndTime(), 1);

                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                Map<String, Float> listMoney = new TreeMap<>(Comparator.naturalOrder());
                for (String key : listTime.keySet()) {
                    listDate.put(key, 0F);
                    listMoney.put(key, (float) 0.00);
                }

                List<String> time = new LinkedList<>();
                List<Float> date = new LinkedList<>();
                List<String> week = new LinkedList<>();
                List<Float> money = new LinkedList<>();
                if (CollUtil.isNotEmpty(operationData)) {
                    time = operationData.get(0).getTime();
                    week = operationData.get(0).getWeek();
                    date = operationData.get(0).getData();
                    money = operationData.get(1).getData();
                }


                if (time.size() != listTime.size()) {
                    Map<String, Float> mapWeekDate = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapWeekMoney = new TreeMap<>(Comparator.naturalOrder());
                    for (int i = 0; i < week.size(); i++) {
                        mapWeekDate.put(week.get(i), date.get(i));
                        mapWeekMoney.put(week.get(i), money.get(i));
                    }

                    listDate.putAll(mapWeekDate);
                    listMoney.putAll(mapWeekMoney);

                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    List<Float> moneyMap = new LinkedList<>();

                    for (String key : listTime.keySet()) {
                        timeMap.add(listTime.get(key));
                        dateMap.add(listDate.get(key));
                        moneyMap.add(listMoney.get(key));
                    }
                    if (CollUtil.isNotEmpty(operationData)) {
                        operationData.get(0).setTime(timeMap);
                        operationData.get(0).setData(dateMap);
                        operationData.get(1).setTime(timeMap);
                        operationData.get(1).setData(moneyMap);
                    }
                }
            } else if (operation.getType().equals(3)) {
                List<String> monthDay = DateTimeUtil.getMonthDay(operation.getStartTime(), operation.getEndTime());
                Map<String, Float> montData = new TreeMap<>();
                Map<String, Float> moneyData = new TreeMap<>();
                for (String k : monthDay) {
                    montData.put(k, 0F);
                    moneyData.put(k, (float) 0.00);
                }
                List<String> time = new LinkedList<>();
                List<Float> date = new LinkedList<>();
                List<Float> money = new LinkedList<>();
                if (CollUtil.isNotEmpty(operationData)) {
                    time = operationData.get(0).getTime();
                    date = operationData.get(0).getData();
                    money = operationData.get(1).getData();
                }


                if (time.size() != monthDay.size()) {
                    Map<String, Float> mapDate = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapMoney = new TreeMap<>(Comparator.naturalOrder());
                    for (int i = 0; i < date.size(); i++) {
                        mapDate.put(time.get(i), date.get(i));
                        mapMoney.put(time.get(i), money.get(i));
                    }
                    montData.putAll(mapDate);
                    moneyData.putAll(mapMoney);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    List<Float> moneyMap = new LinkedList<>();
                    for (String key : montData.keySet()) {
                        timeMap.add(key);
                        dateMap.add(montData.get(key));
                        moneyMap.add(moneyData.get(key));
                    }
                    if (CollUtil.isNotEmpty(operationData)) {
                        operationData.get(0).setTime(timeMap);
                        operationData.get(0).setData(dateMap);
                        operationData.get(1).setTime(timeMap);
                        operationData.get(1).setData(moneyMap);
                    }
                }
            }
        }
        return JsonResult.succ(operationDataList);
    }

    /**
     * 人均调度
     */
    @RequestMapping("/dispatchAverage")
    public JsonResult<List<OperationData<Float>>> dispatchAverage(Operation operation) {

        Assert.hasLength(operation.getStartTime(), "System.startTime.notNull");
        Assert.hasLength(operation.getEndTime(), "System.endTime.notNull");

        /**运维人员*/
        Map<String, Integer> accountBoundCounts = new HashMap<>();

        /**区域分区名字*/
        Map<String, String> names = new HashMap<>();

        /**区域人员*/
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            List<Map<String, Object>> accountBoundCount = accountUserService.getByAccountIdAndType(operation.getAccountIds(), null, DateTimeUtil.getNowTimeYMD());

            for (Map<String, Object> stringObjectMap : accountBoundCount) {
                accountBoundCounts.put("accountId_" + Integer.parseInt(stringObjectMap.get("accountId").toString()), Integer.parseInt(stringObjectMap.get("accountUserCount").toString()));
            }

            /**获取区域名称*/
            List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
            for (Account account : accountList) {
                names.put("accountId_" + account.getAccountId(), account.getName());
            }

        }

        /**分区人员*/
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            List<Map<String, Object>> regionUserCount = georeGionService.getGroupRegionId(operation.getRegionId());
            for (int i = 0; i < regionUserCount.size(); i++) {
                accountBoundCounts.put("regionId_" + Integer.parseInt(regionUserCount.get(i).get("regionId").toString()), Integer.parseInt(regionUserCount.get(i).get("userIdCount").toString()));
            }

            /**获取分区名称*/
            List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
            for (GeoreGion georeGion : geoRegions) {
                names.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
            }
        }

        if (operation.getType() == null) {
            operation.setType(1);
        }

        List<DispatchDaySta> dispatchDayStaList;
        Map<String, DispatchDaySta> mapDis = new TreeMap<>(Comparator.naturalOrder());
        /**日统计*/
        if (operation.getType().equals(1)) {
            if (DateTimeUtil.getYYMMDD(operation.getEndTime()).equals(DateTimeUtil.getNowTimeYMD())) {
                operation.setEndTime(DateTimeUtil.getEndDateTimeBefore(-1));
            }
            dispatchDayStaList = dispatchDayStaService.getByAccountIdDateDay(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());

            for (DispatchDaySta dispatchDaySta : dispatchDayStaList) {
                if (dispatchDaySta.getAccountId() != null) {
                    mapDis.put(dispatchDaySta.getDispatchDayDate() + "accountId_" + dispatchDaySta.getAccountId(), dispatchDaySta);
                } else {
                    mapDis.put(dispatchDaySta.getDispatchDayDate() + "regionId_" + dispatchDaySta.getRegionId(), dispatchDaySta);
                }
            }
        }
        /**周统计*/
        else if (operation.getType().equals(2)) {
            dispatchDayStaList = dispatchDayStaService.getByAccountIdDateWeek(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (DispatchDaySta dispatchDaySta : dispatchDayStaList) {
                if (dispatchDaySta.getAccountId() != null) {
                    mapDis.put(dispatchDaySta.getDateWeek() + "accountId_" + dispatchDaySta.getAccountId(), dispatchDaySta);
                } else {
                    mapDis.put(dispatchDaySta.getDateWeek() + "regionId_" + dispatchDaySta.getRegionId(), dispatchDaySta);
                }
            }
        }
        /** 月统计*/
        else if (operation.getType().equals(3)) {
            dispatchDayStaList = dispatchDayStaService.getByAccountIdDateMonth(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (DispatchDaySta dispatchDaySta : dispatchDayStaList) {
                if (dispatchDaySta.getAccountId() != null) {
                    mapDis.put(dispatchDaySta.getDateMonth() + "accountId_" + dispatchDaySta.getAccountId(), dispatchDaySta);
                } else {
                    mapDis.put(dispatchDaySta.getDateMonth() + "regionId_" + dispatchDaySta.getRegionId(), dispatchDaySta);
                }
            }
        }

        /**拼接数据*/
        Map<String, OperationData<Float>> mapNew = new HashMap<>();
        DecimalFormat df = new DecimalFormat("0.00");
        for (String keyIdDate : mapDis.keySet()) {
            String keyId = null;
            if (operation.getType().equals(1)) {
                keyId = keyIdDate.substring(10);
            } else if (operation.getType().equals(2)) {
                keyId = keyIdDate.substring(6);
            } else if (operation.getType().equals(3)) {
                keyId = keyIdDate.substring(7);
            }
            if (mapNew.get(keyId) == null) {
                OperationData<Float> operationData = new OperationData<>();
                operationData.setName(names.get(keyId));
                // 数据
                List<Float> datas = new LinkedList<>();
                Float data = null;

                if (accountBoundCounts.get(keyId) == null) {
                    data = (float) 0.00;
                } else {
                    if (mapDis.get(keyIdDate).getMeanDispatchCount() == null || mapDis.get(keyIdDate).getMeanDispatchCount().equals(0.00)) {
                        data = Float.parseFloat(df.format((float) mapDis.get(keyIdDate).getDispatchCount() / accountBoundCounts.get(keyId)));
                    } else {
                        data = Float.parseFloat(df.format(mapDis.get(keyIdDate).getMeanDispatchCount()));
                    }

                }

                datas.add(data);
                operationData.setData(datas);

                // 时间
                List<String> times = new LinkedList<>();
                List<String> weeks = new LinkedList<>();
                String time;
                String week;

                if (operation.getType().equals(1)) {
                    time = mapDis.get(keyIdDate).getDispatchDayDate();
                    times.add(time);
                } else if (operation.getType().equals(2)) {
                    week = mapDis.get(keyIdDate).getDateWeek();
                    time = mapDis.get(keyIdDate).getDispatchDayDate();
                    times.add(time);
                    weeks.add(week);
                } else if (operation.getType().equals(3)) {
                    time = mapDis.get(keyIdDate).getDateMonth();
                    times.add(time);
                }
                operationData.setTime(times);
                operationData.setWeek(weeks);

                mapNew.put(keyId, operationData);
            } else {
                if (accountBoundCounts.get(keyId) == null) {
                    mapNew.get(keyId).getData().add((float) 0.00);
                } else {
                    if (mapDis.get(keyIdDate).getMeanDispatchCount() == null || mapDis.get(keyIdDate).getMeanDispatchCount().equals(0.00)) {
                        mapNew.get(keyId).getData().add(Float.parseFloat(df.format((float) mapDis.get(keyIdDate).getDispatchCount() / accountBoundCounts.get(keyId))));
                    } else {
                        mapNew.get(keyId).getData().add(Float.parseFloat(df.format(mapDis.get(keyIdDate).getMeanDispatchCount())));
                    }

                }
                if (operation.getType().equals(1)) {
                    mapNew.get(keyId).getTime().add(mapDis.get(keyIdDate).getDispatchDayDate());
                } else if (operation.getType().equals(2)) {
                    mapNew.get(keyId).getTime().add(mapDis.get(keyIdDate).getDispatchDayDate());
                    mapNew.get(keyId).getWeek().add(mapDis.get(keyIdDate).getDateWeek());
                } else if (operation.getType().equals(3)) {
                    mapNew.get(keyId).getTime().add(mapDis.get(keyIdDate).getDateMonth());
                }
            }
        }

        int size = 0;
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            size += operation.getAccountIds().size();
        }
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            size += operation.getRegionId().size();
        }

        if (mapNew.size() != size) {
            Map<String, Integer> integerMap = new HashMap<>();
            Map<String, String> nameMaps = new HashMap<>();
            if (CollUtil.isNotEmpty(operation.getAccountIds())) {
                for (Integer a : operation.getAccountIds()) {
                    integerMap.put("accountId_" + a, a);
                }

                /**获取区域名称*/
                List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
                for (Account account : accountList) {
                    nameMaps.put("accountId_" + account.getAccountId(), account.getName());
                }

            }
            if (CollUtil.isNotEmpty(operation.getRegionId())) {
                for (Integer r : operation.getRegionId()) {
                    integerMap.put("regionId_" + r, r);
                }

                /**获取分区名称*/
                List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
                for (GeoreGion georeGion : geoRegions) {
                    nameMaps.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
                }
            }

            for (String key : integerMap.keySet()) {
                if (mapNew.get(key) == null) {

                    OperationData<Float> operationDataCount = new OperationData<>();
                    operationDataCount.setName(nameMaps.get(key));

                    List<Float> dataCounts = new LinkedList<>();
                    Float dataCount = (float) 0.00;
                    dataCounts.add(dataCount);
                    operationDataCount.setData(dataCounts);

                    // 时间
                    List<String> times = new LinkedList<>();
                    List<String> weeks = new LinkedList<>();
                    String time;
                    String week;

                    if (operation.getType().equals(1)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        times.add(time);
                    } else if (operation.getType().equals(2)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        week = DateTimeUtil.getStringWeek(operation.getStartTime());
                        times.add(time);
                        weeks.add(week);
                    } else if (operation.getType().equals(3)) {
                        time = operation.getStartTime().substring(0, 7);
                        times.add(time);
                    }
                    operationDataCount.setTime(times);
                    operationDataCount.setWeek(weeks);
                    mapNew.put(key, operationDataCount);
                }
            }
        }

        List<OperationData<Float>> operationDataList = new LinkedList<>();
        for (String key : mapNew.keySet()) {
            operationDataList.add(mapNew.get(key));
        }

        for (OperationData<Float> operationData : operationDataList) {
            /**补充数据*/
            if (operation.getType().equals(1)) {
                List<String> list = DateTimeUtil.findDates(operation.getStartTime(), operation.getEndTime());

                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                for (String i : list) {
                    listDate.put(i, (float) 0);
                }

                List<String> time = operationData.getTime();
                List<Float> date = operationData.getData();

                if (time.size() != listDate.size()) {
                    Map<String, Float> map = new TreeMap<>();
                    for (int i = 0; i < date.size(); i++) {
                        map.put(time.get(i), date.get(i));
                    }
                    listDate.putAll(map);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : listDate.keySet()) {
                        timeMap.add(key);
                        dateMap.add(listDate.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            } else if (operation.getType().equals(2)) {
                Map<String, String> listTime = DateTimeUtil.getDayOfWeekWithinDateInterval(operation.getStartTime(), operation.getEndTime(), 1);

                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                for (String key : listTime.keySet()) {
                    listDate.put(key, (float) 0.00);
                }

                List<String> time;
                List<Float> date;
                List<String> week;
                time = operationData.getTime();
                week = operationData.getWeek();
                date = operationData.getData();

                if (time.size() != listDate.size()) {
                    Map<String, Float> mapWeekDate = new TreeMap<>();
                    for (int i = 0; i < week.size(); i++) {
                        mapWeekDate.put(week.get(i), date.get(i));
                    }
                    listDate.putAll(mapWeekDate);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : listTime.keySet()) {
                        timeMap.add(listTime.get(key));
                        dateMap.add(listDate.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            } else if (operation.getType().equals(3)) {
                List<String> monthDay = DateTimeUtil.getMonthDay(operation.getStartTime(), operation.getEndTime());
                Map<String, Float> montData = new TreeMap<>(Comparator.naturalOrder());
                for (String k : monthDay) {
                    montData.put(k, (float) 0);
                }
                List<String> time = operationData.getTime();
                List<Float> date = operationData.getData();

                if (time.size() != monthDay.size()) {
                    Map<String, Float> map = new TreeMap<>();
                    for (int i = 0; i < date.size(); i++) {
                        map.put(time.get(i), date.get(i));
                    }
                    montData.putAll(map);

                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : montData.keySet()) {
                        timeMap.add(key);
                        dateMap.add(montData.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            }
        }

        return JsonResult.succ(operationDataList);
    }

    /**
     * 人均挪车
     */
    @RequestMapping("/moveAverage")
    public JsonResult<List<OperationData<Float>>> moveAverage(Operation operation) {

        Assert.hasLength(operation.getStartTime(), "System.startTime.notNull");
        Assert.hasLength(operation.getEndTime(), "System.endTime.notNull");


        /**获取运维人员*/
        Map<String, Integer> accountBoundCounts = new HashMap<>();

        /**区域分区名字*/
        Map<String, String> names = new HashMap<>();

        /**区域人员*/
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            List<Map<String, Object>> accountBoundCount = accountUserService.getByAccountIdAndType(operation.getAccountIds(), null, DateTimeUtil.getNowTimeYMD());
            for (Map<String, Object> stringObjectMap : accountBoundCount) {
                accountBoundCounts.put("accountId_" + Integer.parseInt(stringObjectMap.get("accountId").toString()), Integer.parseInt(stringObjectMap.get("accountUserCount").toString()));
            }

            /**获取区域名称*/
            List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
            for (Account account : accountList) {
                names.put("accountId_" + account.getAccountId(), account.getName());
            }
        }

        /**分区人员*/
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            List<Map<String, Object>> regionUserCount = georeGionService.getGroupRegionId(operation.getRegionId());
            for (int i = 0; i < regionUserCount.size(); i++) {
                accountBoundCounts.put("regionId_" + Integer.parseInt(regionUserCount.get(i).get("regionId").toString()), Integer.parseInt(regionUserCount.get(i).get("userIdCount").toString()));
            }

            /**获取分区名称*/
            List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
            for (GeoreGion georeGion : geoRegions) {
                names.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
            }
        }

        if (operation.getType() == null) {
            operation.setType(1);
        }

        List<MoveDaySta> moveDayStaList;
        Map<String, MoveDaySta> mapMov = new TreeMap<>(Comparator.naturalOrder());
        /**日统计*/
        if (operation.getType().equals(1)) {
            if (DateTimeUtil.getYYMMDD(operation.getEndTime()).equals(DateTimeUtil.getNowTimeYMD())) {
                operation.setEndTime(DateTimeUtil.getEndDateTimeBefore(-1));
            }
            moveDayStaList = moveDayStaService.getByAccountIdDateDay(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (MoveDaySta moveDaySta : moveDayStaList) {
                if (moveDaySta.getAccountId() != null) {
                    mapMov.put(moveDaySta.getMoveDayDate() + "accountId_" + moveDaySta.getAccountId(), moveDaySta);
                } else {
                    mapMov.put(moveDaySta.getMoveDayDate() + "regionId_" + moveDaySta.getRegionId(), moveDaySta);
                }
            }
        }
        /**周统计*/
        else if (operation.getType().equals(2)) {
            moveDayStaList = moveDayStaService.getByAccountIdDateWeek(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (MoveDaySta moveDaySta : moveDayStaList) {
                if (moveDaySta.getAccountId() != null) {
                    mapMov.put(moveDaySta.getDateWeek() + "accountId_" + moveDaySta.getAccountId(), moveDaySta);
                } else {
                    mapMov.put(moveDaySta.getDateWeek() + "regionId_" + moveDaySta.getRegionId(), moveDaySta);
                }
            }
        }
        /** 月统计*/
        else if (operation.getType().equals(3)) {
            moveDayStaList = moveDayStaService.getByAccountIdDateMonth(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (MoveDaySta moveDaySta : moveDayStaList) {
                if (moveDaySta.getAccountId() != null) {
                    mapMov.put(moveDaySta.getDateMonth() + "accountId_" + moveDaySta.getAccountId(), moveDaySta);
                } else {
                    mapMov.put(moveDaySta.getDateMonth() + "regionId_" + moveDaySta.getRegionId(), moveDaySta);
                }
            }
        }

        /**拼接数据*/
        Map<String, OperationData<Float>> mapNew = new HashMap<>();
        DecimalFormat df = new DecimalFormat("0.00");
        for (String keyIdDate : mapMov.keySet()) {
            String keyId = null;
            if (operation.getType().equals(1)) {
                keyId = keyIdDate.substring(10);
            } else if (operation.getType().equals(2)) {
                keyId = keyIdDate.substring(6);
            } else if (operation.getType().equals(3)) {
                keyId = keyIdDate.substring(7);
            }
            if (mapNew.get(keyId) == null) {
                OperationData<Float> operationData = new OperationData<>();
                operationData.setName(names.get(keyId));
                // 数据
                List<Float> dataList = new LinkedList<>();
                float data;
                if (accountBoundCounts.get(keyId) == null) {
                    data = (float) 0.00;
                } else {
                    if (mapMov.get(keyIdDate).getMeanMoveCount() == null || mapMov.get(keyIdDate).getMeanMoveCount().equals(0.00)) {
                        data = Float.parseFloat(df.format((float) mapMov.get(keyIdDate).getMoveCount() / accountBoundCounts.get(keyId)));
                    } else {
                        data = Float.parseFloat(df.format(mapMov.get(keyIdDate).getMeanMoveCount()));
                    }
                }
                dataList.add(data);
                operationData.setData(dataList);
                // 时间
                List<String> times = new LinkedList<>();
                List<String> weeks = new LinkedList<>();
                String time;
                String week;

                if (operation.getType().equals(1)) {
                    time = mapMov.get(keyIdDate).getMoveDayDate();
                    times.add(time);
                } else if (operation.getType().equals(2)) {
                    week = mapMov.get(keyIdDate).getDateWeek();
                    time = mapMov.get(keyIdDate).getMoveDayDate();
                    times.add(time);
                    weeks.add(week);
                } else if (operation.getType().equals(3)) {
                    time = mapMov.get(keyIdDate).getDateMonth();
                    times.add(time);
                }
                operationData.setTime(times);
                operationData.setWeek(weeks);

                mapNew.put(keyId, operationData);
            } else {
                if (accountBoundCounts.get(keyId) == null) {
                    mapNew.get(keyId).getData().add((float) 0.00);
                } else {
                    if (mapMov.get(keyIdDate).getMeanMoveCount() == null || mapMov.get(keyIdDate).getMeanMoveCount().equals(0.00)) {
                        mapNew.get(keyId).getData().add(Float.parseFloat(df.format((float) mapMov.get(keyIdDate).getMoveCount() / accountBoundCounts.get(keyId))));
                    } else {
                        mapNew.get(keyId).getData().add(Float.parseFloat(df.format(mapMov.get(keyIdDate).getMeanMoveCount())));
                    }

                }
                if (operation.getType().equals(1)) {
                    mapNew.get(keyId).getTime().add(mapMov.get(keyIdDate).getMoveDayDate());
                } else if (operation.getType().equals(2)) {
                    mapNew.get(keyId).getTime().add(mapMov.get(keyIdDate).getMoveDayDate());
                    mapNew.get(keyId).getWeek().add(mapMov.get(keyIdDate).getDateWeek());
                } else if (operation.getType().equals(3)) {
                    mapNew.get(keyId).getTime().add(mapMov.get(keyIdDate).getDateMonth());
                }
            }
        }

        int size = 0;
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            size += operation.getAccountIds().size();
        }
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            size += operation.getRegionId().size();
        }

        if (mapNew.size() != size) {
            Map<String, Integer> integerMap = new HashMap<>();
            Map<String, String> nameMaps = new HashMap<>();

            if (CollUtil.isNotEmpty(operation.getAccountIds())) {
                for (Integer a : operation.getAccountIds()) {
                    integerMap.put("accountId_" + a, a);
                }

                /**获取区域名称*/
                List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
                for (Account account : accountList) {
                    nameMaps.put("accountId_" + account.getAccountId(), account.getName());
                }

            }
            if (CollUtil.isNotEmpty(operation.getRegionId())) {
                for (Integer r : operation.getRegionId()) {
                    integerMap.put("regionId_" + r, r);
                }

                /**获取分区名称*/
                List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
                for (GeoreGion georeGion : geoRegions) {
                    nameMaps.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
                }
            }
            for (String key : integerMap.keySet()) {
                if (mapNew.get(key) == null) {
                    OperationData<Float> operationDataCount = new OperationData<>();
                    operationDataCount.setName(nameMaps.get(key));

                    List<Float> dataCounts = new LinkedList<>();
                    Float dataCount = (float) 0.00;
                    dataCounts.add(dataCount);
                    operationDataCount.setData(dataCounts);

                    // 时间
                    List<String> times = new LinkedList<>();
                    List<String> weeks = new LinkedList<>();
                    String time;
                    String week;

                    if (operation.getType().equals(1)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        times.add(time);
                    } else if (operation.getType().equals(2)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        week = DateTimeUtil.getStringWeek(operation.getStartTime());
                        times.add(time);
                        weeks.add(week);
                    } else if (operation.getType().equals(3)) {
                        time = operation.getStartTime().substring(0, 7);
                        times.add(time);
                    }
                    operationDataCount.setTime(times);
                    operationDataCount.setWeek(weeks);
                    mapNew.put(key, operationDataCount);
                }
            }
        }

        List<OperationData<Float>> operationDataList = new LinkedList<>();
        for (String key : mapNew.keySet()) {
            operationDataList.add(mapNew.get(key));
        }
        for (OperationData<Float> operationData : operationDataList) {
            /**补充数据*/
            if (operation.getType().equals(1)) {
                List<String> list = DateTimeUtil.findDates(operation.getStartTime(), operation.getEndTime());

                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                for (String i : list) {
                    listDate.put(i, (float) 0);
                }

                List<String> time = operationData.getTime();
                List<Float> date = operationData.getData();

                if (time.size() != listDate.size()) {
                    Map<String, Float> map = new TreeMap<>();
                    for (int i = 0; i < date.size(); i++) {
                        map.put(time.get(i), date.get(i));
                    }
                    listDate.putAll(map);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : listDate.keySet()) {
                        timeMap.add(key);
                        dateMap.add(listDate.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            } else if (operation.getType().equals(2)) {
                Map<String, String> listTime = DateTimeUtil.getDayOfWeekWithinDateInterval(operation.getStartTime(), operation.getEndTime(), 1);

                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                for (String key : listTime.keySet()) {
                    listDate.put(key, (float) 0.00);
                }

                List<String> time;
                List<Float> date;
                List<String> week;
                time = operationData.getTime();
                week = operationData.getWeek();
                date = operationData.getData();

                if (time.size() != listDate.size()) {
                    Map<String, Float> mapWeekDate = new TreeMap<>();
                    for (int i = 0; i < week.size(); i++) {
                        mapWeekDate.put(week.get(i), date.get(i));
                    }
                    listDate.putAll(mapWeekDate);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : listTime.keySet()) {
                        timeMap.add(listTime.get(key));
                        dateMap.add(listDate.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            } else if (operation.getType().equals(3)) {
                List<String> monthDay = DateTimeUtil.getMonthDay(operation.getStartTime(), operation.getEndTime());
                Map<String, Float> montData = new TreeMap<>(Comparator.naturalOrder());
                for (String k : monthDay) {
                    montData.put(k, (float) 0);
                }
                List<String> time = operationData.getTime();
                List<Float> date = operationData.getData();

                if (time.size() != monthDay.size()) {
                    Map<String, Float> map = new TreeMap<>();
                    for (int i = 0; i < date.size(); i++) {
                        map.put(time.get(i), date.get(i));
                    }
                    montData.putAll(map);

                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : montData.keySet()) {
                        timeMap.add(key);
                        dateMap.add(montData.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            }
        }
        return JsonResult.succ(operationDataList);
    }

    /**
     * 人均换电
     */
    @RequestMapping("/powerAverage")
    public JsonResult<List<OperationData<Float>>> powerAverage(Operation operation) {

        Assert.hasLength(operation.getStartTime(), "System.startTime.notNull");
        Assert.hasLength(operation.getEndTime(), "System.endTime.notNull");

        /**获取运维人员*/
        Map<String, Integer> accountBoundCounts = new HashMap<>();

        /**区域分区名字*/
        Map<String, String> names = new HashMap<>();

        /**区域人员*/
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            List<Map<String, Object>> accountBoundCount = accountUserService.getByAccountIdAndType(operation.getAccountIds(), null, DateTimeUtil.getNowTimeYMD());

            for (Map<String, Object> stringObjectMap : accountBoundCount) {
                accountBoundCounts.put("accountId_" + Integer.parseInt(stringObjectMap.get("accountId").toString()), Integer.parseInt(stringObjectMap.get("accountUserCount").toString()));
            }

            /**获取区域名称*/
            List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
            for (Account account : accountList) {
                names.put("accountId_" + account.getAccountId(), account.getName());
            }

        }

        /**分区人员*/
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            List<Map<String, Object>> regionUserCount = georeGionService.getGroupRegionId(operation.getRegionId());
            for (Map<String, Object> stringObjectMap : regionUserCount) {
                accountBoundCounts.put("regionId_" + Integer.parseInt(stringObjectMap.get("regionId").toString()), Integer.parseInt(stringObjectMap.get("userIdCount").toString()));
            }

            /**获取分区名称*/
            List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
            for (GeoreGion georeGion : geoRegions) {
                names.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
            }
        }

        if (operation.getType() == null) {
            operation.setType(1);
        }

        List<PowerDaySta> powerDayStaList;
        Map<String, PowerDaySta> mapPow = new TreeMap<>(Comparator.naturalOrder());
        /**日统计*/
        if (operation.getType().equals(1)) {
            if (DateTimeUtil.getYYMMDD(operation.getEndTime()).equals(DateTimeUtil.getNowTimeYMD())) {
                operation.setEndTime(DateTimeUtil.getEndDateTimeBefore(-1));
            }
            powerDayStaList = powerDayStaService.getByAccountIdDateDay(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (PowerDaySta powerDaySta : powerDayStaList) {
                if (powerDaySta.getAccountId() != null) {
                    mapPow.put(powerDaySta.getPowerDayDate() + "accountId_" + powerDaySta.getAccountId(), powerDaySta);
                } else {
                    mapPow.put(powerDaySta.getPowerDayDate() + "regionId_" + powerDaySta.getRegionId(), powerDaySta);
                }
            }
        }
        /**周统计*/
        else if (operation.getType().equals(2)) {
            powerDayStaList = powerDayStaService.getByAccountIdDateWeek(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (PowerDaySta powerDaySta : powerDayStaList) {
                if (powerDaySta.getAccountId() != null) {
                    mapPow.put(powerDaySta.getDateWeek() + "accountId_" + powerDaySta.getAccountId(), powerDaySta);
                } else {
                    mapPow.put(powerDaySta.getDateWeek() + "regionId_" + powerDaySta.getRegionId(), powerDaySta);
                }
            }
        }
        /** 月统计*/
        else if (operation.getType().equals(3)) {
            powerDayStaList = powerDayStaService.getByAccountIdDateMonth(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (PowerDaySta powerDaySta : powerDayStaList) {
                if (powerDaySta.getAccountId() != null) {
                    mapPow.put(powerDaySta.getDateMonth() + "accountId_" + powerDaySta.getAccountId(), powerDaySta);
                } else {
                    mapPow.put(powerDaySta.getDateMonth() + "regionId_" + powerDaySta.getRegionId(), powerDaySta);
                }
            }
        }

        /**拼接数据*/
        Map<String, OperationData<Float>> mapNew = new HashMap<>();
        DecimalFormat df = new DecimalFormat("0.00");
        for (String keyIdDate : mapPow.keySet()) {
            String keyId = null;
            if (operation.getType().equals(1)) {
                keyId = keyIdDate.substring(10);
            } else if (operation.getType().equals(2)) {
                keyId = keyIdDate.substring(6);
            } else if (operation.getType().equals(3)) {
                keyId = keyIdDate.substring(7);
            }
            if (mapNew.get(keyId) == null) {
                OperationData<Float> operationData = new OperationData<>();
                operationData.setName(names.get(keyId));
                // 数据
                List<Float> dataList = new LinkedList<>();
                float data;
                if (accountBoundCounts.get(keyId) == null) {
                    data = (float) 0.00;
                } else {
                    if (mapPow.get(keyIdDate).getMeanPowerCount() == null || mapPow.get(keyIdDate).getMeanPowerCount().equals(0.00)) {
                        data = Float.parseFloat(df.format((float) mapPow.get(keyIdDate).getPowerCount() / accountBoundCounts.get(keyId)));
                    } else {
                        data = Float.parseFloat(df.format(mapPow.get(keyIdDate).getMeanPowerCount()));
                    }

                }
                dataList.add(data);
                operationData.setData(dataList);
                // 时间
                List<String> times = new LinkedList<>();
                List<String> weeks = new LinkedList<>();
                String time;
                String week;

                if (operation.getType().equals(1)) {
                    time = mapPow.get(keyIdDate).getPowerDayDate();
                    times.add(time);
                } else if (operation.getType().equals(2)) {
                    week = mapPow.get(keyIdDate).getDateWeek();
                    time = mapPow.get(keyIdDate).getPowerDayDate();
                    times.add(time);
                    weeks.add(week);
                } else if (operation.getType().equals(3)) {
                    time = mapPow.get(keyIdDate).getDateMonth();
                    times.add(time);
                }
                operationData.setTime(times);
                operationData.setWeek(weeks);

                mapNew.put(keyId, operationData);
            } else {
                if (accountBoundCounts.get(keyId) == null) {
                    mapNew.get(keyId).getData().add((float) 0.00);
                } else {
                    if (mapPow.get(keyIdDate).getMeanPowerCount() == null || mapPow.get(keyIdDate).getMeanPowerCount().equals(0.00)) {
                        mapNew.get(keyId).getData().add(Float.parseFloat(df.format((float) mapPow.get(keyIdDate).getPowerCount() / accountBoundCounts.get(keyId))));
                    } else {
                        mapNew.get(keyId).getData().add(Float.parseFloat(df.format(mapPow.get(keyIdDate).getMeanPowerCount())));
                    }

                }
                if (operation.getType().equals(1)) {
                    mapNew.get(keyId).getTime().add(mapPow.get(keyIdDate).getPowerDayDate());
                } else if (operation.getType().equals(2)) {
                    mapNew.get(keyId).getTime().add(mapPow.get(keyIdDate).getPowerDayDate());
                    mapNew.get(keyId).getWeek().add(mapPow.get(keyIdDate).getDateWeek());
                } else if (operation.getType().equals(3)) {
                    mapNew.get(keyId).getTime().add(mapPow.get(keyIdDate).getDateMonth());
                }
            }
        }

        int size = 0;
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            size += operation.getAccountIds().size();
        }
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            size += operation.getRegionId().size();
        }

        if (mapNew.size() != size) {
            Map<String, Integer> integerMap = new HashMap<>();
            Map<String, String> nameMaps = new HashMap<>();

            if (CollUtil.isNotEmpty(operation.getAccountIds())) {
                for (Integer a : operation.getAccountIds()) {
                    integerMap.put("accountId_" + a, a);
                }

                /**获取区域名称*/
                List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
                for (Account account : accountList) {
                    nameMaps.put("accountId_" + account.getAccountId(), account.getName());
                }

            }
            if (CollUtil.isNotEmpty(operation.getRegionId())) {
                for (Integer r : operation.getRegionId()) {
                    integerMap.put("regionId_" + r, r);
                }

                /**获取分区名称*/
                List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
                for (GeoreGion georeGion : geoRegions) {
                    nameMaps.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
                }
            }
            for (String key : integerMap.keySet()) {
                if (mapNew.get(key) == null) {
                    OperationData<Float> operationDataCount = new OperationData<>();
                    operationDataCount.setName(nameMaps.get(key));

                    List<Float> dataCounts = new LinkedList<>();
                    Float dataCount = (float) 0.00;
                    dataCounts.add(dataCount);
                    operationDataCount.setData(dataCounts);

                    // 时间
                    List<String> times = new LinkedList<>();
                    List<String> weeks = new LinkedList<>();
                    String time;
                    String week;

                    if (operation.getType().equals(1)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        times.add(time);
                    } else if (operation.getType().equals(2)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        week = DateTimeUtil.getStringWeek(operation.getStartTime());
                        times.add(time);
                        weeks.add(week);
                    } else if (operation.getType().equals(3)) {
                        time = operation.getStartTime().substring(0, 7);
                        times.add(time);
                    }
                    operationDataCount.setTime(times);
                    operationDataCount.setWeek(weeks);
                    mapNew.put(key, operationDataCount);
                }
            }
        }

        List<OperationData<Float>> operationDataList = new LinkedList<>();
        for (String key : mapNew.keySet()) {
            operationDataList.add(mapNew.get(key));
        }
        for (OperationData<Float> operationData : operationDataList) {
            /**补充数据*/
            if (operation.getType().equals(1)) {
                List<String> list = DateTimeUtil.findDates(operation.getStartTime(), operation.getEndTime());

                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                for (String i : list) {
                    listDate.put(i, (float) 0);
                }

                List<String> time = operationData.getTime();
                List<Float> date = operationData.getData();

                if (time.size() != listDate.size()) {
                    Map<String, Float> map = new TreeMap<>();
                    for (int i = 0; i < date.size(); i++) {
                        map.put(time.get(i), date.get(i));
                    }
                    listDate.putAll(map);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : listDate.keySet()) {
                        timeMap.add(key);
                        dateMap.add(listDate.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            } else if (operation.getType().equals(2)) {
                Map<String, String> listTime = DateTimeUtil.getDayOfWeekWithinDateInterval(operation.getStartTime(), operation.getEndTime(), 1);

                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                for (String key : listTime.keySet()) {
                    listDate.put(key, (float) 0.00);
                }

                List<String> time;
                List<Float> date;
                List<String> week;
                time = operationData.getTime();
                week = operationData.getWeek();
                date = operationData.getData();

                if (time.size() != listDate.size()) {
                    Map<String, Float> mapWeekDate = new TreeMap<>();
                    for (int i = 0; i < week.size(); i++) {
                        mapWeekDate.put(week.get(i), date.get(i));
                    }
                    listDate.putAll(mapWeekDate);
                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : listTime.keySet()) {
                        timeMap.add(listTime.get(key));
                        dateMap.add(listDate.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            } else if (operation.getType().equals(3)) {
                List<String> monthDay = DateTimeUtil.getMonthDay(operation.getStartTime(), operation.getEndTime());
                Map<String, Float> montData = new TreeMap<>(Comparator.naturalOrder());
                for (String k : monthDay) {
                    montData.put(k, (float) 0);
                }
                List<String> time = operationData.getTime();
                List<Float> date = operationData.getData();

                if (time.size() != monthDay.size()) {
                    Map<String, Float> map = new TreeMap<>();
                    for (int i = 0; i < date.size(); i++) {
                        map.put(time.get(i), date.get(i));
                    }
                    montData.putAll(map);

                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    for (String key : montData.keySet()) {
                        timeMap.add(key);
                        dateMap.add(montData.get(key));
                    }
                    operationData.setTime(timeMap);
                    operationData.setData(dateMap);
                }
            }
        }

        return JsonResult.succ(operationDataList);
    }

    /**
     * 车辆占比查询
     */
    @RequestMapping("/notUseMachine")
    public JsonResult<List<List<OperationData<Float>>>> notUseMachine(Operation operation) {

        Assert.hasLength(operation.getStartTime(), "System.startTime.notNull");
        Assert.hasLength(operation.getEndTime(), "System.endTime.notNull");

        /** 获取车辆数*/
        Map<String, Integer> carCounts = new HashMap<>();
        /**区域分区名字*/
        Map<String, String> names = new HashMap<>();

        /**区域车辆*/
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            List<Map<String, Object>> carCount = machineService.getGroupByDay(operation.getAccountIds());
            for (Map<String, Object> stringObjectMap : carCount) {
                carCounts.put("accountId_" + stringObjectMap.get("accountId"), Integer.parseInt(stringObjectMap.get("machineNoCount").toString()));
            }

            /**获取区域名称*/
            List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
            for (Account account : accountList) {
                names.put("accountId_" + account.getAccountId(), account.getName());
            }
        }

        /**分区车辆*/
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            List<Map<String, Object>> regionUserCount = georeMachineService.getMachine(operation.getRegionId());
            for (Map<String, Object> stringObjectMap : regionUserCount) {
                carCounts.put("regionId_" + stringObjectMap.get("regionId"), Integer.parseInt(stringObjectMap.get("machineCount").toString()));
            }

            /**获取分区名称*/
            List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
            for (GeoreGion georeGion : geoRegions) {
                names.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
            }
        }

        if (operation.getType() == null) {
            operation.setType(1);
        }
        List<MachineDaySta> machineDayStaList;

        Map<String, MachineDaySta> mapMac = new TreeMap<>(Comparator.naturalOrder());

        /**日统计*/
        if (operation.getType().equals(1)) {
            if (DateTimeUtil.getYYMMDD(operation.getEndTime()).equals(DateTimeUtil.getNowTimeYMD())) {
                operation.setEndTime(DateTimeUtil.getEndDateTimeBefore(-1));
            }
            machineDayStaList = machineDayStaService.getByAccountIdDateDay(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (MachineDaySta machineDaySta : machineDayStaList) {
                if (machineDaySta.getAccountId() != null) {
                    mapMac.put(machineDaySta.getMachineDate() + "accountId_" + machineDaySta.getAccountId(), machineDaySta);
                } else {
                    mapMac.put(machineDaySta.getMachineDate() + "regionId_" + machineDaySta.getRegionId(), machineDaySta);
                }
            }
        }

        /**周统计*/
        else if (operation.getType().equals(2)) {
            machineDayStaList = machineDayStaService.getByAccountIdDateWeek(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (MachineDaySta machineDaySta : machineDayStaList) {
                if (machineDaySta.getAccountId() != null) {
                    mapMac.put(machineDaySta.getDateWeek() + "accountId_" + machineDaySta.getAccountId(), machineDaySta);
                } else {
                    mapMac.put(machineDaySta.getDateWeek() + "regionId_" + machineDaySta.getRegionId(), machineDaySta);
                }
            }
        }
        /** 月统计*/
        else if (operation.getType().equals(3)) {
            machineDayStaList = machineDayStaService.getByAccountIdDateMonth(operation.getAccountIds(), operation.getRegionId(), operation.getStartTime(), operation.getEndTime());
            for (MachineDaySta machineDaySta : machineDayStaList) {
                if (machineDaySta.getAccountId() != null) {
                    mapMac.put(machineDaySta.getDateMonth() + "accountId_" + machineDaySta.getAccountId(), machineDaySta);
                } else {
                    mapMac.put(machineDaySta.getDateMonth() + "regionId_" + machineDaySta.getRegionId(), machineDaySta);
                }
            }
        }

        /**拼接数据*/
        Map<String, List<OperationData<Float>>> mapNew = new HashMap<>();
        for (String keyIdDate : mapMac.keySet()) {
            String keyId = null;
            if (operation.getType().equals(1)) {
                keyId = keyIdDate.substring(10);
            } else if (operation.getType().equals(2)) {
                keyId = keyIdDate.substring(6);
            } else if (operation.getType().equals(3)) {
                keyId = keyIdDate.substring(7);
            }
            if (mapNew.get(keyId) == null) {
                List<OperationData<Float>> operationDataList = new LinkedList<>();

                OperationData<Float> useMachineCount = new OperationData<>();
                OperationData<Float> lackPowerMachineCount = new OperationData<>();
                OperationData<Float> lackParkPoint = new OperationData<>();
                OperationData<Float> lackFault = new OperationData<>();
                OperationData<Float> lackState = new OperationData<>();
                OperationData<Float> lackBorrow = new OperationData<>();

                useMachineCount.setName(names.get(keyId));
                lackPowerMachineCount.setName(names.get(keyId));
                lackParkPoint.setName(names.get(keyId));
                lackFault.setName(names.get(keyId));
                lackState.setName(names.get(keyId));
                lackBorrow.setName(names.get(keyId));

                // 不可运营车辆占比
                List<Float> dataUserMachines = new LinkedList<>();
                float dataUserMachine;
                // 缺电车辆占比
                List<Float> dataLackPowers = new LinkedList<>();
                float dataLackPower;
                // 站外车辆占比
                List<Float> dataLackParkPoints = new LinkedList<>();
                float dataLackParkPoint;
                // 故障车辆占比
                List<Float> dataLackFaults = new LinkedList<>();
                float dataLackFault;
                // 无信号车辆占比
                List<Float> dataLackStates = new LinkedList<>();
                float dataLackState;
                // 闲置车辆占比
                List<Float> dataLackBorrows = new LinkedList<>();
                float dataLackBorrow;


                DecimalFormat df = new DecimalFormat("0.00");
                if (carCounts.get(keyId) == null) {
                    dataUserMachine = (float) 0.00;
                    dataLackPower = (float) 0.00;
                    dataLackParkPoint = (float) 0.00;
                    dataLackFault = (float) 0.00;
                    dataLackState = (float) 0.00;
                    dataLackBorrow = (float) 0.00;
                } else {
                    dataUserMachine = Float.parseFloat(df.format((carCounts.get(keyId) - mapMac.get(keyIdDate).getUseMachineCount()) / carCounts.get(keyId)));
                    dataLackPower = Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackPowerMachineCount() / carCounts.get(keyId)));

                    dataLackParkPoint = Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackParkpoint() / carCounts.get(keyId)));
                    dataLackFault = Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackFault() / carCounts.get(keyId)));
                    dataLackState = Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackState() / carCounts.get(keyId)));
                    dataLackBorrow = Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackBorrow() / carCounts.get(keyId)));
                }
                dataUserMachines.add(dataUserMachine);
                useMachineCount.setData(dataUserMachines);

                dataLackPowers.add(dataLackPower);
                lackPowerMachineCount.setData(dataLackPowers);

                dataLackParkPoints.add(dataLackParkPoint);
                lackParkPoint.setData(dataLackParkPoints);

                dataLackFaults.add(dataLackFault);
                lackFault.setData(dataLackFaults);

                dataLackStates.add(dataLackState);
                lackState.setData(dataLackStates);

                dataLackBorrows.add(dataLackBorrow);
                lackBorrow.setData(dataLackBorrows);

                // 时间
                List<String> times = new LinkedList<>();
                List<String> weeks = new LinkedList<>();
                String time;
                String week;

                if (operation.getType().equals(1)) {
                    time = mapMac.get(keyIdDate).getMachineDate();
                    times.add(time);
                } else if (operation.getType().equals(2)) {
                    time = mapMac.get(keyIdDate).getMachineDate();
                    week = mapMac.get(keyIdDate).getDateWeek();
                    times.add(time);
                    weeks.add(week);
                } else if (operation.getType().equals(3)) {
                    time = mapMac.get(keyIdDate).getDateMonth();
                    times.add(time);
                }

                useMachineCount.setTime(times);
                useMachineCount.setWeek(weeks);
                lackPowerMachineCount.setTime(times);
                lackPowerMachineCount.setWeek(weeks);
                lackParkPoint.setTime(times);
                lackParkPoint.setWeek(weeks);
                lackFault.setTime(times);
                lackFault.setWeek(weeks);
                lackState.setTime(times);
                lackState.setWeek(weeks);
                lackBorrow.setTime(times);
                lackBorrow.setWeek(weeks);

                operationDataList.add(useMachineCount);
                operationDataList.add(lackPowerMachineCount);
                operationDataList.add(lackParkPoint);
                operationDataList.add(lackFault);
                operationDataList.add(lackState);
                operationDataList.add(lackBorrow);
                mapNew.put(keyId, operationDataList);
            } else {
                DecimalFormat df = new DecimalFormat("0.00");
                if (carCounts.get(keyId) == null) {
                    mapNew.get(keyId).get(0).getData().add((float) 0.00);
                    mapNew.get(keyId).get(1).getData().add((float) 0.00);

                    mapNew.get(keyId).get(2).getData().add((float) 0.00);
                    mapNew.get(keyId).get(3).getData().add((float) 0.00);
                    mapNew.get(keyId).get(4).getData().add((float) 0.00);
                    mapNew.get(keyId).get(5).getData().add((float) 0.00);
                } else {
                    mapNew.get(keyId).get(0).getData().add(Float.parseFloat(df.format((carCounts.get(keyId) - mapMac.get(keyIdDate).getUseMachineCount()) / carCounts.get(keyId))));
                    mapNew.get(keyId).get(1).getData().add(Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackPowerMachineCount() / carCounts.get(keyId))));
                    mapNew.get(keyId).get(2).getData().add(Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackParkpoint() / carCounts.get(keyId))));
                    mapNew.get(keyId).get(3).getData().add(Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackFault() / carCounts.get(keyId))));
                    mapNew.get(keyId).get(4).getData().add(Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackState() / carCounts.get(keyId))));
                    mapNew.get(keyId).get(5).getData().add(Float.parseFloat(df.format(mapMac.get(keyIdDate).getLackBorrow() / carCounts.get(keyId))));
                }
                if (operation.getType().equals(1)) {
                    mapNew.get(keyId).get(0).getTime().add(mapMac.get(keyIdDate).getMachineDate());
                } else if (operation.getType().equals(2)) {
                    mapNew.get(keyId).get(0).getTime().add(mapMac.get(keyIdDate).getMachineDate());
                    mapNew.get(keyId).get(0).getWeek().add(mapMac.get(keyIdDate).getDateWeek());
                } else if (operation.getType().equals(3)) {
                    mapNew.get(keyId).get(0).getTime().add(mapMac.get(keyIdDate).getDateMonth());
                }
            }
        }

        int size = 0;
        if (CollUtil.isNotEmpty(operation.getAccountIds())) {
            size += operation.getAccountIds().size();
        }
        if (CollUtil.isNotEmpty(operation.getRegionId())) {
            size += operation.getRegionId().size();
        }

        if (mapNew.size() != size) {
            Map<String, Integer> integerMap = new HashMap<>();
            Map<String, String> nameMaps = new HashMap<>();

            if (CollUtil.isNotEmpty(operation.getAccountIds())) {
                for (Integer a : operation.getAccountIds()) {
                    integerMap.put("accountId_" + a, a);
                }

                /**获取区域名称*/
                List<Account> accountList = accountService.getAccountIds(operation.getAccountIds());
                for (Account account : accountList) {
                    nameMaps.put("accountId_" + account.getAccountId(), account.getName());
                }

            }
            if (CollUtil.isNotEmpty(operation.getRegionId())) {
                for (Integer r : operation.getRegionId()) {
                    integerMap.put("regionId_" + r, r);
                }

                /**获取分区名称*/
                List<GeoreGion> geoRegions = georeGionService.getByRegionIds(operation.getRegionId());
                for (GeoreGion georeGion : geoRegions) {
                    nameMaps.put("regionId_" + georeGion.getRegionId(), georeGion.getRegionName());
                }
            }
            for (String key : integerMap.keySet()) {
                if (mapNew.get(key) == null) {
                    List<OperationData<Float>> operationDataList = new LinkedList<>();

                    OperationData<Float> operationDataCount = new OperationData<>();
                    OperationData<Float> operationDataMoney = new OperationData<>();
                    OperationData<Float> operationDataParkPoint = new OperationData<>();
                    OperationData<Float> operationDataFault = new OperationData<>();
                    OperationData<Float> operationDataState = new OperationData<>();
                    OperationData<Float> operationDataBorrow = new OperationData<>();


                    operationDataCount.setName(nameMaps.get(key));
                    operationDataMoney.setName(nameMaps.get(key));
                    operationDataParkPoint.setName(nameMaps.get(key));
                    operationDataFault.setName(nameMaps.get(key));
                    operationDataState.setName(nameMaps.get(key));
                    operationDataBorrow.setName(nameMaps.get(key));

                    List<Float> dataCounts = new LinkedList<>();
                    List<Float> dataMoneys = new LinkedList<>();
                    List<Float> dataParkPoints = new LinkedList<>();
                    List<Float> dataFaults = new LinkedList<>();
                    List<Float> dataStates = new LinkedList<>();
                    List<Float> dataBorrows = new LinkedList<>();

                    Float dataCount = (float) 0.00;
                    Float dataMoney = (float) 0.00;
                    Float dataParkPoint = (float) 0.00;
                    Float dataFault = (float) 0.00;
                    Float dataState = (float) 0.00;
                    Float dataBorrow = (float) 0.00;

                    dataCounts.add(dataCount);
                    dataMoneys.add(dataMoney);
                    dataParkPoints.add(dataParkPoint);
                    dataFaults.add(dataFault);
                    dataStates.add(dataState);
                    dataBorrows.add(dataBorrow);

                    operationDataCount.setData(dataCounts);
                    operationDataMoney.setData(dataMoneys);
                    operationDataParkPoint.setData(dataParkPoints);
                    operationDataFault.setData(dataFaults);
                    operationDataState.setData(dataStates);
                    operationDataBorrow.setData(dataBorrows);

                    // 时间
                    List<String> times = new LinkedList<>();
                    List<String> weeks = new LinkedList<>();
                    String time;
                    String week;

                    if (operation.getType().equals(1)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        times.add(time);
                    } else if (operation.getType().equals(2)) {
                        time = DateTimeUtil.getYYMMDD(operation.getStartTime());
                        week = DateTimeUtil.getStringWeek(operation.getStartTime());
                        times.add(time);
                        weeks.add(week);
                    } else if (operation.getType().equals(3)) {
                        time = operation.getStartTime().substring(0, 7);
                        times.add(time);
                    }
                    operationDataCount.setTime(times);
                    operationDataCount.setWeek(weeks);
                    operationDataMoney.setTime(times);
                    operationDataMoney.setWeek(weeks);
                    operationDataParkPoint.setTime(times);
                    operationDataParkPoint.setWeek(weeks);
                    operationDataFault.setTime(times);
                    operationDataFault.setWeek(weeks);
                    operationDataState.setTime(times);
                    operationDataState.setWeek(weeks);
                    operationDataBorrow.setTime(times);
                    operationDataBorrow.setWeek(weeks);

                    operationDataList.add(operationDataCount);
                    operationDataList.add(operationDataMoney);
                    operationDataList.add(operationDataParkPoint);
                    operationDataList.add(operationDataFault);
                    operationDataList.add(operationDataState);
                    operationDataList.add(operationDataBorrow);
                    mapNew.put(key, operationDataList);
                }
            }
        }

        List<List<OperationData<Float>>> operationDataList = new LinkedList<>();
        for (String key : mapNew.keySet()) {
            operationDataList.add(mapNew.get(key));
        }

        for (List<OperationData<Float>> operationData : operationDataList) {
            /**补充数据*/
            if (operation.getType().equals(1)) {
                List<String> list = DateTimeUtil.findDates(operation.getStartTime(), operation.getEndTime());
                Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                Map<String, Float> listMoney = new TreeMap<>(Comparator.naturalOrder());
                Map<String, Float> listParkPoint = new TreeMap<>(Comparator.naturalOrder());
                Map<String, Float> listFault = new TreeMap<>(Comparator.naturalOrder());
                Map<String, Float> listState = new TreeMap<>(Comparator.naturalOrder());
                Map<String, Float> listBorrow = new TreeMap<>(Comparator.naturalOrder());
                for (String i : list) {
                    listDate.put(i, (float) 0.00);
                    listMoney.put(i, (float) 0.00);

                    listParkPoint.put(i, (float) 0.00);
                    listFault.put(i, (float) 0.00);
                    listState.put(i, (float) 0.00);
                    listBorrow.put(i, (float) 0.00);
                }

                List<String> time = new LinkedList<>();
                List<Float> dateCount = new LinkedList<>();
                List<Float> dateMoney = new LinkedList<>();
                List<Float> dateParkpint = new LinkedList<>();
                List<Float> dateFault = new LinkedList<>();
                List<Float> dateState = new LinkedList<>();
                List<Float> dateBorrow = new LinkedList<>();

                if (CollUtil.isNotEmpty(operationData)) {
                    time = operationData.get(0).getTime();
                    dateCount = operationData.get(0).getData();
                    dateMoney = operationData.get(1).getData();
                    dateParkpint = operationData.get(2).getData();
                    dateFault = operationData.get(3).getData();
                    dateState = operationData.get(4).getData();
                    dateBorrow = operationData.get(5).getData();
                }

                if (time.size() != listDate.size()) {
                    Map<String, Float> mapCount = new TreeMap<>();
                    Map<String, Float> mapMoney = new TreeMap<>();
                    Map<String, Float> mapParkPoint = new TreeMap<>();
                    Map<String, Float> mapFault = new TreeMap<>();
                    Map<String, Float> mapState = new TreeMap<>();
                    Map<String, Float> mapBorrow = new TreeMap<>();
                    for (int i = 0; i < dateCount.size(); i++) {
                        mapCount.put(time.get(i), dateCount.get(i));
                        mapMoney.put(time.get(i), dateMoney.get(i));
                        mapParkPoint.put(time.get(i), dateParkpint.get(i));
                        mapFault.put(time.get(i), dateFault.get(i));
                        mapState.put(time.get(i), dateState.get(i));
                        mapBorrow.put(time.get(i), dateBorrow.get(i));
                    }
                    listDate.putAll(mapCount);
                    listMoney.putAll(mapMoney);
                    listParkPoint.putAll(mapParkPoint);
                    listFault.putAll(mapFault);
                    listState.putAll(mapState);
                    listBorrow.putAll(mapBorrow);

                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    List<Float> moneyMap = new LinkedList<>();
                    List<Float> parkPointMap = new LinkedList<>();
                    List<Float> faultMap = new LinkedList<>();
                    List<Float> stateMap = new LinkedList<>();
                    List<Float> borrowMap = new LinkedList<>();
                    for (String key : listDate.keySet()) {
                        timeMap.add(key);
                        dateMap.add(listDate.get(key));
                        moneyMap.add(listMoney.get(key));
                        parkPointMap.add(listParkPoint.get(key));
                        faultMap.add(listFault.get(key));
                        stateMap.add(listState.get(key));
                        borrowMap.add(listBorrow.get(key));
                    }
                    if (CollUtil.isNotEmpty(operationData)) {
                        operationData.get(0).setTime(timeMap);
                        operationData.get(0).setData(dateMap);
                        operationData.get(1).setTime(timeMap);
                        operationData.get(1).setData(moneyMap);
                        operationData.get(2).setTime(timeMap);
                        operationData.get(2).setData(parkPointMap);
                        operationData.get(3).setTime(timeMap);
                        operationData.get(3).setData(faultMap);
                        operationData.get(4).setTime(timeMap);
                        operationData.get(4).setData(stateMap);
                        operationData.get(5).setTime(timeMap);
                        operationData.get(5).setData(borrowMap);
                    }
                }
            } else if (operation.getType().equals(2)) {
                Map<String, String> listTime = DateTimeUtil.getDayOfWeekWithinDateInterval(operation.getStartTime(), operation.getEndTime(), 1);

                List<String> time = new LinkedList<>();
                List<Float> date = new LinkedList<>();
                List<String> week = new LinkedList<>();
                List<Float> money = new LinkedList<>();

                List<Float> parkpoint = new LinkedList<>();
                List<Float> fault = new LinkedList<>();
                List<Float> state = new LinkedList<>();
                List<Float> borrow = new LinkedList<>();
                if (CollUtil.isNotEmpty(operationData)) {
                    time = operationData.get(0).getTime();
                    week = operationData.get(0).getWeek();
                    date = operationData.get(0).getData();
                    money = operationData.get(1).getData();
                    parkpoint = operationData.get(2).getData();
                    fault = operationData.get(3).getData();
                    state = operationData.get(4).getData();
                    borrow = operationData.get(5).getData();
                }

                if (time.size() != listTime.size()) {

                    Map<String, Float> listDate = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> listMoney = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> listParkPoint = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> listFault = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> listState = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> listBorrow = new TreeMap<>(Comparator.naturalOrder());
                    for (String key : listTime.keySet()) {
                        listDate.put(key, 0F);
                        listMoney.put(key, (float) 0.00);

                        listParkPoint.put(key, (float) 0.00);
                        listFault.put(key, (float) 0.00);
                        listState.put(key, (float) 0.00);
                        listBorrow.put(key, (float) 0.00);
                    }

                    Map<String, Float> mapWeekDate = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapWeekMoney = new TreeMap<>(Comparator.naturalOrder());

                    Map<String, Float> mapWeekParkPoint = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapWeekFault = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapWeekState = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapWeekBorrow = new TreeMap<>(Comparator.naturalOrder());
                    for (int i = 0; i < week.size(); i++) {
                        mapWeekDate.put(week.get(i), date.get(i));
                        mapWeekMoney.put(week.get(i), money.get(i));

                        mapWeekParkPoint.put(week.get(i), parkpoint.get(i));
                        mapWeekFault.put(week.get(i), fault.get(i));
                        mapWeekState.put(week.get(i), state.get(i));
                        mapWeekBorrow.put(week.get(i), borrow.get(i));
                    }
                    listDate.putAll(mapWeekDate);
                    listMoney.putAll(mapWeekMoney);
                    listParkPoint.putAll(mapWeekParkPoint);
                    listFault.putAll(mapWeekFault);
                    listState.putAll(mapWeekState);
                    listBorrow.putAll(mapWeekBorrow);

                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    List<Float> moneyMap = new LinkedList<>();

                    List<Float> parkPointMap = new LinkedList<>();
                    List<Float> faultMap = new LinkedList<>();
                    List<Float> stateMap = new LinkedList<>();
                    List<Float> borrowMap = new LinkedList<>();
                    for (String key : listTime.keySet()) {
                        timeMap.add(listTime.get(key));
                        dateMap.add(listDate.get(key));
                        moneyMap.add(listMoney.get(key));

                        parkPointMap.add(listParkPoint.get(key));
                        faultMap.add(listFault.get(key));
                        stateMap.add(listState.get(key));
                        borrowMap.add(listBorrow.get(key));
                    }
                    if (CollUtil.isNotEmpty(operationData)) {
                        operationData.get(0).setTime(timeMap);
                        operationData.get(0).setData(dateMap);
                        operationData.get(1).setTime(timeMap);
                        operationData.get(1).setData(moneyMap);

                        operationData.get(2).setTime(timeMap);
                        operationData.get(2).setData(parkPointMap);
                        operationData.get(3).setTime(timeMap);
                        operationData.get(3).setData(faultMap);
                        operationData.get(4).setTime(timeMap);
                        operationData.get(4).setData(stateMap);
                        operationData.get(5).setTime(timeMap);
                        operationData.get(5).setData(borrowMap);
                    }
                }
            } else if (operation.getType().equals(3)) {
                List<String> monthDay = DateTimeUtil.getMonthDay(operation.getStartTime(), operation.getEndTime());
                Map<String, Float> montData = new TreeMap<>();
                Map<String, Float> moneyData = new TreeMap<>();

                Map<String, Float> parkPointData = new TreeMap<>();
                Map<String, Float> faultData = new TreeMap<>();
                Map<String, Float> stateData = new TreeMap<>();
                Map<String, Float> borrowData = new TreeMap<>();
                for (String k : monthDay) {
                    montData.put(k, 0F);
                    moneyData.put(k, (float) 0.00);

                    parkPointData.put(k, (float) 0.00);
                    faultData.put(k, (float) 0.00);
                    stateData.put(k, (float) 0.00);
                    borrowData.put(k, (float) 0.00);
                }
                List<String> time = new LinkedList<>();
                List<Float> date = new LinkedList<>();
                List<Float> money = new LinkedList<>();

                List<Float> parkpoint = new LinkedList<>();
                List<Float> fault = new LinkedList<>();
                List<Float> state = new LinkedList<>();
                List<Float> borrow = new LinkedList<>();
                if (CollUtil.isNotEmpty(operationData)) {
                    time = operationData.get(0).getTime();
                    date = operationData.get(0).getData();
                    money = operationData.get(1).getData();
                    parkpoint = operationData.get(1).getData();
                    fault = operationData.get(1).getData();
                    state = operationData.get(1).getData();
                    borrow = operationData.get(1).getData();
                }


                if (time.size() != monthDay.size()) {
                    Map<String, Float> mapDate = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapMoney = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapParkPoint = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapFault = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapState = new TreeMap<>(Comparator.naturalOrder());
                    Map<String, Float> mapBorrow = new TreeMap<>(Comparator.naturalOrder());
                    for (int i = 0; i < date.size(); i++) {
                        mapDate.put(time.get(i), date.get(i));
                        mapMoney.put(time.get(i), money.get(i));
                        mapParkPoint.put(time.get(i), parkpoint.get(i));
                        mapFault.put(time.get(i), fault.get(i));
                        mapState.put(time.get(i), state.get(i));
                        mapBorrow.put(time.get(i), borrow.get(i));
                    }
                    montData.putAll(mapDate);
                    moneyData.putAll(mapMoney);

                    parkPointData.putAll(mapParkPoint);
                    faultData.putAll(mapFault);
                    stateData.putAll(mapState);
                    borrowData.putAll(mapBorrow);

                    List<String> timeMap = new LinkedList<>();
                    List<Float> dateMap = new LinkedList<>();
                    List<Float> moneyMap = new LinkedList<>();

                    List<Float> parkPointMap = new LinkedList<>();
                    List<Float> faultMap = new LinkedList<>();
                    List<Float> stateMap = new LinkedList<>();
                    List<Float> borrowMap = new LinkedList<>();
                    for (String key : montData.keySet()) {
                        timeMap.add(key);
                        dateMap.add(montData.get(key));
                        moneyMap.add(moneyData.get(key));
                        parkPointMap.add(parkPointData.get(key));
                        faultMap.add(faultData.get(key));
                        stateMap.add(stateData.get(key));
                        borrowMap.add(borrowData.get(key));
                    }
                    if (CollUtil.isNotEmpty(operationData)) {
                        operationData.get(0).setTime(timeMap);
                        operationData.get(0).setData(dateMap);
                        operationData.get(1).setTime(timeMap);
                        operationData.get(1).setData(moneyMap);

                        operationData.get(2).setTime(timeMap);
                        operationData.get(2).setData(parkPointMap);
                        operationData.get(3).setTime(timeMap);
                        operationData.get(3).setData(faultMap);
                        operationData.get(4).setTime(timeMap);
                        operationData.get(4).setData(stateMap);
                        operationData.get(5).setTime(timeMap);
                        operationData.get(5).setData(borrowMap);
                    }
                }
            }
        }

        return JsonResult.succ(operationDataList);
    }

    /**
     * 品牌下运营区域基本信息
     */
    @RequestMapping("/simpleMessage")
    public JsonResult<List<SimpleMessage>> simpleMessage(String token,
                                    @RequestParam(value = "startTime", required = false) String startTime,
                                    @RequestParam(value = "endTime", required = false) String endTime) {

        AccountUser accountUser = tokenService.getAccount(token);

        /** 获取运营区域信息 */
        List<Account> accounts = new ArrayList<>();
        // 品牌
        Integer accountUserType = accountUser.getAccountUserType();
        if (accountService.getCountHolderAgent(accountUser.getAccountUserId()) > 0) {
            accounts = accountService.getHolderAgent(accountUser.getAccountUserId());
        } else if ((accountUserType.equals(UserConstant.ACCOUNT_BRAND) ||
                accountUser.getRole().getRoleLevel().equals(UserConstant.ACCOUNT_BRAND))
                && !accountUserType.equals(UserConstant.ACCOUNT_FRANCHISEE)
                && !accountUserType.equals(UserConstant.ACCOUNT_ADOPT)) {
            // 加载品牌下的所有运营区域
            accounts = accountService.getBrandAgent(accountUser.getAccountId());
        }
        // 加盟商
        else if ((accountUserType.equals(UserConstant.ACCOUNT_AREA) ||
                accountUser.getRole().getRoleLevel().equals(UserConstant.ACCOUNT_AREA))
                && !accountUserType.equals(UserConstant.ACCOUNT_FRANCHISEE)) {
            // 加载加盟商下面的所有运营区域
            accounts = accountService.getByParentId(accountUser.getAccountId());
        }
        // 领养人
        else if (accountUserType.equals(UserConstant.ACCOUNT_ADOPT)) {
        }
        // 区域运营商、运维管理员、运维人员
        else {
            List<Integer> accountIds = new ArrayList<>();
            accountIds.add(accountUser.getAccountId());
            accounts = accountService.getByAccountIds(accountIds);
        }

        List<Integer> accountIds = new LinkedList<>();
        for (Account account : accounts) {
            accountIds.add(account.getAccountId());
        }

        // 用户数
        List<Map<String, Object>> accountUserCount = userService.getUserCountByAccountIds(accountIds);

        Map<Integer, Integer> accountBoundCounts = new HashMap<>();
        for (Map<String, Object> map : accountUserCount) {
            accountBoundCounts.put(Integer.parseInt(map.get("accountId").toString()), Integer.parseInt(map.get("accountUserCount").toString()));
        }

        // 车辆数
        List<Map<String, Object>> accountMachineCount = machineService.getCountByAccountIds(accountIds);

        Map<Integer, Integer> accountMachineCounts = new HashMap<>();
        for (Map<String, Object> stringObjectMap : accountMachineCount) {
            accountMachineCounts.put(Integer.parseInt(stringObjectMap.get("accountId").toString()), Integer.parseInt(stringObjectMap.get("machineCount").toString()));
        }

        // 订单数
        Map<Integer, Long> orderCumsMap = new HashMap<>();
        if (startTime == null) {
            List<AccountSumStat> accountSumStats = accountSumStatService.getAccountIdsTypeDate(accountIds, AccountDayStatConstant.CYCLING_INCOME, null);
            for (AccountSumStat accountSumStat : accountSumStats) {
                orderCumsMap.put(accountSumStat.getAccountId(), accountSumStat.getCntTotal());
            }

        } else {
            List<AccountDayStat> accountDayStats = accountDayStatService.getAccountIdsTypeDate(accountIds, AccountDayStatConstant.CYCLING_INCOME, startTime, endTime);
            for (AccountDayStat accountDayStat : accountDayStats) {
                orderCumsMap.put(accountDayStat.getAccountId(), accountDayStat.getCntTotal());
            }
        }

        List<SimpleMessage> simpleMessageList = new LinkedList<>();
        for (Account account : accounts) {
            SimpleMessage simpleMessage = new SimpleMessage();
            simpleMessage.setAccountId(account.getAccountId());
            simpleMessage.setName(account.getName());
            simpleMessage.setUserTotal(accountBoundCounts.get(account.getAccountId()) == null ? 0 : accountBoundCounts.get(account.getAccountId()));
            simpleMessage.setMachineTotal(accountMachineCounts.get(account.getAccountId()) == null ? 0 : accountMachineCounts.get(account.getAccountId()));
            simpleMessage.setOrderTotal((orderCumsMap.get(account.getAccountId()) == null ? 0 : orderCumsMap.get(account.getAccountId())));
            simpleMessageList.add(simpleMessage);
        }

        return JsonResult.succ(simpleMessageList);
    }
}
